package com.songshuai.customer.client.service.impl;

import com.songshuai.customer.client.dao.customer.SopMapper;
import com.songshuai.customer.client.dto.request.sop.DynamicSopListReqDto;
import com.songshuai.customer.client.dto.request.sop.SopListReqDto;
import com.songshuai.customer.client.dto.response.sop.DynamicSopListResDto;
import com.songshuai.customer.client.dto.response.sop.SopListResDto;
import com.songshuai.customer.client.service.SopService;
import com.songshuai.webapi.baseapi.enumerations.ResultStatus;
import com.songshuai.webapi.baseapi.exception.BusinessException;
import com.songshuai.webapi.baseapi.pojo.BaseParmDto;
import com.songshuai.webapi.baseapi.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author:wbl
 * @Date: 2019/3/18
 */
@Service
public class SopServiceImpl implements SopService {

    @Autowired
    private SopMapper sopMapper;


    @Override
    public PageUtil getSopListByType(BaseParmDto<SopListReqDto> request) {
        try{
            Integer count = sopMapper.getSopListByTypeCount(request.getParam());
            //设置分页
            PageUtil page = new PageUtil(request.getPageIndex(), request.getPageSize(), count);
            request.getParam().setStart(page.getStart());
            request.getParam().setEnd(page.getEnd());
            List<SopListResDto> resList = sopMapper.getSopListByType(request.getParam());
            page.setLists(resList);
            return page;
        }catch (Exception e) {
            throw new BusinessException(ResultStatus.ERROR_SEARCH_FAILED.getErrorMsg(), ResultStatus.FAILOfficial);
        }
    }

    @Override
    public PageUtil getDynamicSopList(BaseParmDto<DynamicSopListReqDto> request) {
        try{
            Integer count = sopMapper.getDynamicSopListCount(request.getParam());
            //设置分页
            PageUtil page = new PageUtil(request.getPageIndex(), request.getPageSize(), count);
            request.getParam().setStart(page.getStart());
            request.getParam().setEnd(page.getEnd());
            List<DynamicSopListResDto> resList = sopMapper.getDynamicSopList(request.getParam());
            page.setLists(resList);
            return page;
        }catch (Exception e) {
            throw new BusinessException(ResultStatus.ERROR_SEARCH_FAILED.getErrorMsg(), ResultStatus.FAILOfficial);
        }
    }


}
